{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "788b2357-4b45-46a0-acd7-1406beb7440e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "bb2da91a-61aa-4212-a0c4-ba27b6ff214e",
   "metadata": {},
   "source": [
    "## 1. 关系表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db3ddc5c-595e-450c-a2ca-132fb76fa903",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a42eca57-d684-42ba-a1d0-6da0a660c9a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "类型 = '便携'\n",
    "价格 = 499.99\n",
    "\n",
    "(类型 == '便携' or 类型 == '迷你') and 价格 < 1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1ac1abd5-539f-40cb-a19a-81ab313d45c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "价格 = 499.99\n",
    "\n",
    "100 <= 价格  and 价格 <= 500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b071f31a-48d1-4dd7-b292-28e75f9fc10a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "价格 = 499.99\n",
    "\n",
    "100 <= 价格 <= 500"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a241cf8a-0d41-479b-aa03-c74a6d8165ef",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "## 2. 浮点的关系运算 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dc4132d0-9660-4694-8132-0ad574bedf14",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 0.1 + 0.2\n",
    "b = 0.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "009ffe44-bee8-45a5-adf0-cb8bacc6d392",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8187d41-d1d1-411f-b84b-eceb1dab7788",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "64a9d24c-451d-4a5f-8216-edf954c0e1c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.551115123125783e-17"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abs(a - b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4506f735-4c70-4812-be64-9d49ffc9b22a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abs(a - b) < 1e-10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e47e7c18-1437-4199-b61e-df97c62c87b1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4be4c4ae-99f3-4453-887f-bd033284eefc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "math.isclose(0.1 + 0.2, 0.3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "105fab40-ddb1-4f9d-9a0d-6d24c8e0d505",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "af1e3ae5-248e-4582-8961-0d81ce258694",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math.isclose(0.1 + 0.2, 0.3, rel_tol=1e-20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c844c708-9e05-4d36-b1f5-29009550393f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "197cd646-886e-4a8d-90a9-7d5b41612f74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 0.1 + 0.2\n",
    "b = 0.3\n",
    "a <= b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "7ff7ef7d-9225-4011-83a9-f49ef2b5b151",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 0.1 + 0.2\n",
    "b = 0.3\n",
    "\n",
    "math.isclose(a, b) or (a < b)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
